﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Torch_Services
{
    public class OverdueCostStandardService : IOverdueCostStandardService
    {
        private IOverdueCostStandardDal _overCost;
        private IMapper _mapper;
        public OverdueCostStandardService(IOverdueCostStandardDal overCost, IMapper mapper)
        {
            _overCost = overCost;
            _mapper = mapper;
        }

        public async Task<int> AddOverdueCostStandardAsync(int overdueCost)
        {
            return await _overCost.AddAsync(new Overduecoststandard 
            {
                OverdueCost = overdueCost
            });
        }

        public async  Task<int> DeleteOverdueCostStandardAsync(int id)
        {
            var data = await _overCost.QueryAsync(id);
            return data == null ? -1 : await _overCost.DeleteAsync(data);
        }

        public async  Task<int> EditOverdueCostStandardAsync(int id, int overdueCost)
        {
            var data = await _overCost.QueryAsync(id);
            if (data == null)
                return -1;
            data.OverdueCost = overdueCost;
            return await _overCost.EditAsync(data);
        }

        public async  Task<List<OverdueCostStandardDto>> QueryOverdueCostStandardAllAsync()
        {
            var data = await _overCost.QueryAsync();
            return _mapper.Map<List<Overduecoststandard>, List<OverdueCostStandardDto>>(data);
        }

        public async Task<OverdueCostStandardDto> QueryOverdueCostStandardByIdAsync(int id)
        {
            var data = await _overCost.QueryAsync(id);
            return _mapper.Map<Overduecoststandard, OverdueCostStandardDto>(data);
        }
    }
}
